/**
 * @typedef ChatRecord
 * @property {string} toId.required
 * @property {number} pageNo.required
 * @property {number} pageSize.required
 */

/**
 * @typedef ReadMessage
 * @property {string} fromId.required
 * @property {number} sendTimeStamp.required
 */

/**
 * @typedef DeleteIm
 * @property {string} imId.required
 */

/**
 * @typedef DeleteImPerson
 * @property {string} toId.required
 */

const express = require('express')
const router = express.Router()
const auth = require('@/middleware/auth.middleware')
const imController = require('@/controllers/im.controller')

/**
 * 查询用户聊天成员列表
 * @route POST /im/chat-person-list
 * @group im聊天管理
 * @returns {object} 200
 * @returns {Error}  default - Unexpected error
 * @security JWT
 */
router.post('/chat-person-list', auth(), imController.findChatPersonList)

/**
 * 查询与指定用户的聊天记录
 * @route POST /im/chat-record-list
 * @group im聊天管理
 * @param {ChatRecord.model} chatRecord.body.required
 * @returns {object} 200
 * @returns {Error}  default - Unexpected error
 * @security JWT
 */
router.post('/chat-record-list', auth(), imController.findChatRecordPage)

/**
 * 删除聊天记录
 * @route POST /im/delete-im-record
 * @group im聊天管理
 * @param {DeleteIm.model} deleteIm.body.required
 * @returns {object} 200
 * @returns {Error}  default - Unexpected error
 * @security JWT
 */
router.post('/delete-im-record', auth(), imController.deleteIm)

/**
 * 删除指定聊天人的所有聊天记录
 * @route POST /im/delete-im-person
 * @group im聊天管理
 * @param {DeleteImPerson.model} deleteImPerson.body.required
 * @returns {object} 200
 * @returns {Error}  default - Unexpected error
 * @security JWT
 */
router.post('/delete-im-person', auth(), imController.deleteChatPerson)

/**
 * 批量已读消息
 * @route POST /im/read-message
 * @group im聊天管理
 * @param {ReadMessage.model} readMessage.body.required
 * @returns {object} 200
 * @returns {Error}  default - Unexpected error
 * @security JWT
 */
router.post('/read-message', auth(), imController.batchReadMessage)

/**
 * 置顶聊天
 * @route GET /im/setTop
 * @group im聊天管理
 * @param {string} toId.query.required
 * @returns {object} 200
 * @returns {Error}  default - Unexpected error
 * @security JWT
 */
router.get('/setTop', auth(), imController.topIm)

/**
 * 撤回聊天
 * @route GET /im/revocate-im
 * @group im聊天管理
 * @param {string} imId.query.required
 * @returns {object} 200
 * @returns {Error}  default - Unexpected error
 * @security JWT
 */
router.get('/revocate-im', auth(), (req, response) => imController.revocationIm(req, response))

/**
 * 取消置顶聊天
 * @route GET /im/resetTop
 * @group im聊天管理
 * @param {string} toId.query.required
 * @returns {object} 200
 * @returns {Error}  default - Unexpected error
 * @security JWT
 */
router.get('/resetTop', auth(), imController.resetTopIm)

module.exports = router
